from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5 import QtGui


import sys

class LineEditDemo(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(LineEditDemo, self).__init__(parent)

        self.setWindowTitle("LineEditdemo ")

        normalLineEdit = QtWidgets.QLineEdit()
        normalLineEdit.setPlaceholderText("normal")
        normalLineEdit.setEchoMode(QtWidgets.QLineEdit.Normal)

        noEchoLineEdit = QtWidgets.QLineEdit()
        noEchoLineEdit.setPlaceholderText("No Echo")
        noEchoLineEdit.setEchoMode(QtWidgets.QLineEdit.NoEcho)

        pswLineEdit = QtWidgets.QLineEdit()
        pswLineEdit.setPlaceholderText("password")
        pswLineEdit.setEchoMode(QtWidgets.QLineEdit.Password)

        pswEchoOnLineEdit = QtWidgets.QLineEdit()
        pswEchoOnLineEdit.setPlaceholderText("password echo on edit")
        pswEchoOnLineEdit.setEchoMode(QtWidgets.QLineEdit.PasswordEchoOnEdit)

        flo = QtWidgets.QFormLayout()
        flo.addRow("Normal", normalLineEdit)
        flo.addRow("NoEcho", noEchoLineEdit)
        flo.addRow("password", pswLineEdit)
        flo.addRow("password Echo On Edit", pswEchoOnLineEdit)

        self.setLayout(flo)

class LineEditDemo2(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(LineEditDemo2, self).__init__(parent)

        self.setWindowTitle("QLineEdit例子")

        self.src_screen_size = QtWidgets.QLineEdit()
        self.src_screen_size.setText("2590 1630")

        self.dst_screen_size = QtWidgets.QLineEdit()
        self.dst_screen_size.setText("1600 900")

        self.src_position = QtWidgets.QLineEdit()

        self.result = QtWidgets.QLineEdit()

        calc_button = QtWidgets.QPushButton()
        calc_button.clicked.connect(self.calc_clicked)
        calc_button.setText("Ok")

        flo = QtWidgets.QFormLayout()
        flo.addRow("原始屏幕尺寸", self.src_screen_size)
        flo.addRow("目标屏幕尺寸", self.dst_screen_size)
        flo.addRow("控件坐标", self.src_position)
        flo.addRow("结果",self.result)
        flo.addRow(calc_button)

        self.setLayout(flo)
    def calc_clicked(self):
        src_screen_str = self.src_screen_size.text().split(' ')
        src_screen_float = [float(v) for v in src_screen_str]

        dst_screen_str = self.dst_screen_size.text().split(' ')
        dst_screen_float = [float(v) for v in dst_screen_str]

        src_str = self.src_position.text().split(' ')
        src_float = [float(v) for v in src_str]

        x = (dst_screen_float[0] * src_float[0]) / src_screen_float[0]
        y = (dst_screen_float[1] * src_float[1]) / src_screen_float[1]
        width = (dst_screen_float[0] * src_float[2]) / src_screen_float[0]
        height = (dst_screen_float[1] * src_float[3]) / src_screen_float[1]

        self.result.setText("{} {} {} {}".format(int(x + 0.5), int(y+0.5),int(width + 0.5), int(height+0.5)))
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    win = LineEditDemo2()
    win.show()
    sys.exit(app.exec_())